//组托详表

/* const {
	stringify
} = require("querystring");
 */
//右滑关闭
mui.init({
	swipeBack: true,
})
var fs = true;
var UserNO = localStorage.getItem("UserName");
window.onload = function() {

	mui.plusReady(function() {
		var currentwindow = plus.webview.currentWebview();
		if (currentwindow.WorkOrderNO != '' && currentwindow.WorkOrderNO != undefined) {
			$("#WorkOrderNO").val(currentwindow.WorkOrderNO);
			$("#MatNO").val(currentwindow.MaterialNO);
			$("#MaterialName").val(currentwindow.MaterialName);
		} else {
			mui.toast("未带入参数。", {
				duration: '1000',
				type: 'div'
			});
		}

		//物料条码扫描
		$("#txtBarcodeNO").keyup(function(event) {
			console.log(event);
			if (event.keyCode == 13) {
				var BarCodeNO = $("#txtBarcodeNO").val();
				var workorderNO = $("#WorkOrderNO").val();
				var typesWork = $("#OrderIndex").val();
				const radioContainer = document.getElementById('radioContainer');
				if (BarCodeNO === null || BarCodeNO === undefined) {
					mui.toast("请扫描料盘条码。", {
						duration: '1000',
						type: 'div'
					});
					BarCodeNO.focus();
				}

				xccpostAsync("JyhstWebASHX.ashx", {
					Action: "CboLines",
					BarCodeNO: BarCodeNO,
					typesWork: typesWork,
					workorderNO: workorderNO,
					UserNO: UserNO
				}, function(data) {
					document.activeElement.blur();
					if (data.Code === 200) {
						// 清空容器
						radioContainer.innerHTML = '';
						for (var i = 0; i < data.ResultData.length; i++) {
							const radioId = `radioOption_${i}`;
							const radioElement = document.createElement('div');
							radioElement.className = 'mui-radio';

							radioElement.innerHTML = `
							                        <input name="stationRadio" type="radio" id="${radioId}" value="${data.ResultData[i]}" ${i === 0 ? 'checked' : ''}>
							                        <label for="${radioId}">${data.ResultData[i]}</label>
							                    `;

							radioContainer.appendChild(radioElement);
						}
						// $("#StationList").html(html); // 清空并插入新内容
						$("#txtResult").val("料盘扫描成功.");
					} else {
						mui.toast("扫描失败.", {
							duration: '1000',
							type: 'div'
						});
						$("#txtResult").val(data.Message);
						$("#txtBarcodeNO").val('');
						$("#txtBarcodeNO").focus();
						document.activeElement.blur();
					}
					plus.nativeUI.closeWaiting(); //关闭转圈圈特效
				}, function(error) {
					console.log("没有数据....");
					$("#txtBarcodeNO").val('');
					$("#txtBarcodeNO").focus();
					plus.nativeUI.closeWaiting(); //关闭转圈圈特效
				});
				// event.preventDefault();
				// event.stopPropagation();
			}

		});

		//关闭等待框

		plus.nativeUI.closeWaiting();
		//显示当前页面
		//mui.currentWebview.show();
	});
}

function OnFast() {
	var BarCodeNO = $("#txtBarcodeNO").val();
	var StationNO = $("#txtLineNO").val();
	var workorderNO = $("#WorkOrderNO").val();
	var typesWork = $("#OrderIndex").val();
	var StationNO = $('input[name="stationRadio"]:checked').val();
	if (BarCodeNO === null || BarCodeNO === undefined) {
		mui.toast("请扫描料盘条码。", {
			duration: '1000',
			type: 'div'
		});
		BarCodeNO.focus();
	}
	xccpostAsync("JyhstWebASHX.ashx", {
		Action: "SMTPutOnMaterialBarcode",
		BarCodeNO: BarCodeNO,
		typesWork: typesWork,
		workorderNO: workorderNO,
		StationNO: StationNO,
		UserNO: UserNO
	}, function(data) {
		console.log(JSON.stringify(data));
		if (data.Code == "200") {
			mui.toast("操作成功.", {
				duration: '1000',
				type: 'div'
			});
			$("#txtResult").val(BarCodeNO + "上料成功,料站为:" + StationNO);
			document.getElementById('radioContainer').innerHTML = '';
			$("#txtBarcodeNO").val('');
			$("#txtBarcodeNO").focus();
		} else {
			mui.toast("扫描失败.", {
				duration: '1000',
				type: 'div'
			});
			$("#txtResult").val(data.Message);
			$("#txtBarcodeNO").val('');
			$("#txtBarcodeNO").focus();
			Audios();
		}
		plus.nativeUI.closeWaiting();
	}, function(error) {
		console.log("没有数据....");
		$("#txtBarcodeNO").val('');
		$("#txtBarcodeNO").focus();
		Audios();
		plus.nativeUI.closeWaiting();
	});


}

//失败报警
function Audios() {
	var audio = new Audio('../../../fonts/baojin.mp3');

	audio.play();
}